<!-- 操盘必读 -->
<template>
    <div class="guide">
        <!-- 大事提醒 -->
        <yn-com-comTitle name="大事提醒" :more="isMore" :moreUrl="'companyEvent'"></yn-com-comTitle>
        <yn-event-remind :data="remind" title="大事提醒"></yn-event-remind>
        <!-- 公司概况 -->
        <yn-com-comTitle
            class="mt15"
            name="公司概况"
            :more="isMore"
            :moreUrl="'company'"
        ></yn-com-comTitle>
        <yn-guide-profile :data="profile"></yn-guide-profile>
        <!-- 最新指标 -->
        <yn-com-comTitle
            class="mt15"
            name="最新指标"
            :more="isMore"
            :moreUrl="'finance'"
        ></yn-com-comTitle>
        <yn-guide-quota :data="quota"></yn-guide-quota>
        <!-- 股东分析 -->
        <yn-com-comTitle
            class="mt15"
            name="股东分析"
            :more="isMore"
            :moreUrl="'partner'"
        ></yn-com-comTitle>
        <div class="partner">
            <yn-partner-partnerNum :data="holder"></yn-partner-partnerNum>
        </div>
        <!-- 核心题材 -->
        <yn-com-comTitle
            class="mt15"
            name="核心题材"
            :more="isMore"
            :moreUrl="'coreTheme'"
        ></yn-com-comTitle>
        <yn-guide-theme :data="theme"></yn-guide-theme>
        <!-- 龙虎榜 -->
        <yn-com-comTitle
            class="mt15"
            name="龙虎榜"
            :more="isMore"
            :moreUrl="'companyEvent'"
        ></yn-com-comTitle>
        <div class="companyEvent">
            <yn-event-excrChange :data="excrChange"></yn-event-excrChange>
        </div>
        <!-- 公司新闻 -->
        <yn-com-comTitle
            class="mt15"
            name="公司新闻"
            :more="isMore"
            :moreUrl="'notice'"
        ></yn-com-comTitle>
        <div class="newNotice">
            <yn-com-comList :data="news" title="公司新闻"></yn-com-comList>
        </div>
        <!-- 公司公告 -->
        <yn-com-comTitle class="mt15" name="公司公告" :more="isMore" :moreUrl="'notice'"></yn-com-comTitle>
        <div class="newNotice">
            <yn-com-comList :data="notice" title="公司公告" infoType="2"></yn-com-comList>
        </div>
    </div>
</template>

<script>
import {
    guideProfile,
    guideHolder,
    guideNews,
    corpNew,
    corpNotice,
} from "../script/api";
//股东分析
const className = (ops) => {
    let val = "";
    val = ops != 0 && ops > 0 ? "colorRed" : "colorGreen";
    if (ops == 0 || ops == null) {
        val = "";
    }
    return {val, name: ops};
};
const handleNum = (arr) => {
    return arr.map((item) => {
        item._totShrPctB = item.totShrPctB ? item.totShrPctB : "--";
        item._totShrPctA = item.totShrPctA ? item.totShrPctA : "--";

        item._avgNumQtrGr = className(item.avgNumQtrGr).name;
        item._avgNumQtrGrClass = className(item.avgNumQtrGr).val;

        item._avgPctQtrGr = className(item.avgPctQtrGr).name;
        item._avgPctQtrGrClass = className(item.avgPctQtrGr).val;

        item._avgNum6MthGr = className(item.avgNum6MthGr).name;
        item._avgNum6MthGrClass = className(item.avgNum6MthGr).val;

        item._avgPct6MthGr = className(item.avgPct6MthGr).name;
        item._avgPct6MthGrClass = className(item.avgPct6MthGr).val;
        return item;
    });
};
//数据格式转化----数据处理
const handle = (arr, ops) => {
    let len = Math.ceil(arr.length / 2);
    let res = [];
    let data = [];
    for (let i = 1; i <= len; i++) {
        let tr = i * 2;
        res = [];
        data.push(res);
        for (let j = 1; j <= arr.length; j++) {
            if (j > tr - 2 && j <= tr) {
                const idx = arr[j - 1];
                idx._infoType = ops;
                idx._title = idx.titleMain ? idx.titleMain : idx.title;
                idx._negaPosiMark =
                    idx.negaPosiMark || idx.negaPosiMark == 0
                        ? ["中", "负", "正"][idx.negaPosiMark]
                        : "";
                idx._color =
                    idx.negaPosiMark || idx.negaPosiMark == 0
                        ? ["tableSignWhite", "tableSignGreen", "tableSignRed"][
                            idx.negaPosiMark
                            ]
                        : "";
                res.push(idx);
            }
        }
    }
    return data;
};
export default {
    data() {
        return {
            isMore: true,
            remind: [], //大事提醒
            profile: {}, //公司概况
            quota: {}, //最新指标
            excrChange: {}, //龙虎榜-买入-卖入
            // buy: [], //龙虎榜-买入
            // sell: [], //龙虎榜-卖入
            theme: [], //核心题材
            holder: [], //股东分析
            news: [], //公司新闻
            notice: [], //公司公告
        };
    },
    mounted() {
        this.getData();
    },
    methods: {
        async getData() {
            const res = await guideProfile();
            this.remind = res.event;
            this.profile = res.profile;
            this.quota = res.quota;
            /////////////////////////////////
            const resHolder = await guideHolder();
            this.holder = handleNum(resHolder.holder);
            this.theme = resHolder.theme;
            let dragonTiger = {};
            dragonTiger.buy = resHolder.buy;
            dragonTiger.sell = resHolder.sell;
            this.excrChange = dragonTiger;
            /////////////////////////////////
            // const resNews = await guideNews();
            // this.news = handle(resNews.news, "1");
            // this.notice = handle(resNews.notice, "2");
            const resNews = await corpNew(); //新闻
            this.news = handle(resNews.data.content, "1");
            const notice = await corpNotice(); //公告
            this.notice = handle(notice.data.list, "2");
        },
    },
};
</script>
<style lang="scss" scoped></style>
